<?php

namespace App\Dao\Task;

use Yj\Daos\BaseDao;
use App\Model\Task\TaskHelp;
use Hyperf\Database\Model\Builder;
use Yj\Daos\BaseDaos;
use Yj\Daos\Verify;
use Hyperf\Utils\Collection;

/**
 * @var TaskHelp
 * @method $this params($params)
 */
class TaskHelpDao extends BaseDaos
{

    public function searchParams(Collection $params)
    {
        $search = $this->getSearch();
        $params->check('keyword', function ($keyword) use ($search) {
            $search->where('title', 'like', '%' . $keyword . '%');
        });
        return $search;
    }


    public function lists(Collection $params)
    {
        $data = $this->params($params)->with('TaskHelpCategory')->orderByDesc("id")->getList();
        return $data;
    }

    public function add(Collection $params)
    {
        $data = $this->create($params->toArray());
        return $data;
    }

    public function edit(int $id, Collection $params)
    {
        $data = $this->DaoWhere(["id" => $id])->firstOrError();
        $data->fill($params->toArray());
        return $data->save();
    }

    public function del(int $id)
    {

        $data = $this->DaoWhere(["id" => $id])->firstOrError();
        return $data->delete();
    }

    public function read($id)
    {
        return $this->where('id', $id)->firstOrError();
    }
}
